import path from 'path';
import webpack from 'webpack';
import { defineConfig } from 'wx-build';

export default defineConfig({
  cache: true,
  caseSensitive: false,
  esbuild: false,
  happy: false,
  extractCss: false,
  inject: {
    title: 'DLJ Center',
    favicon: path.resolve(__dirname, 'public/favicon.ico'),
  },
  eslint: false,
  externals: {
    react: 'React',
    'react-dom': 'ReactDOM',
    moment: 'moment',
  },
  less: {
    modifyVars: {
      // '@primary-color': '#0b7980',
    },
  },
  injectScripts: [
    '//static.assure.com/js/lib/moment.js/2.29.1/moment.min.js',
    '//static.assure.com/js/lib/react/17.0.2/umd/react.production.min.js',
    '//static.assure.com/js/lib/react-dom/17.0.2/umd/react-dom.production.min.js',
  ],
  extraBabelPlugins: [
    [
      require.resolve('babel-plugin-import'),
      {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
      },
    ],
  ],
  server(config) {
    config.proxy = {
      '/proxyHopeServer': {
        target: 'http://192.168.10.27:8080/',
        pathRewrite: { '^/proxyHopeServer': '' },
      },
    };
  },
  webpack(config, context) {
    config.resolve!.fallback = {
      assert: require.resolve('assert/'),
      util: require.resolve('util/'),
      url: require.resolve('url'),
      path: require.resolve('path-browserify'),
      buffer: require.resolve('buffer/'),
      stream: require.resolve('stream-browserify/'),
    };
    config.resolve!.alias = {
      ...config.resolve!.alias,
      process: 'process/browser',
    };
    config.plugins!.push(
      new webpack.ProvidePlugin({
        process: 'process/browser',
      })
    );
    return config;
  },
});
